package dev.ece.suit.loader;

import org.apache.commons.lang3.StringUtils;

import dev.ece.core.texture.Texture;

/**
 * 材质
 * @author 潜行的虚影
 */
public class Material extends dev.ece.core.light.Material {

	private String textureName;
	
	private Texture texture;
	
	private boolean existTexture;
	
	public Material() {}
	
	public Material(String textureName) {
		this.textureName = textureName;
	}
	
	public Material(Texture texture) {
		this.setTexture(texture);
	}
	
	public void setup() {
		if(!this.isExistTexture() && StringUtils.isNotBlank(textureName)) {
			this.setTexture(TextureFactory.createTexture(textureName));
			Texture.unbind();
		}
	}
	
	public boolean isExistTexture() {
		return existTexture;
	}

	protected void setExistTexture(boolean existTexture) {
		this.existTexture = existTexture;
	}
	
	public Texture getTexture() {
		return texture;
	}

	protected void setTexture(Texture texture) {
		this.texture = texture;
		this.setExistTexture(texture != null);
	}

	protected void setTextureName(String textureName) {
		this.textureName = textureName;
	}

	public String getTextureName() {
		return textureName;
	}
	
	public void destroy() {
		if(this.isExistTexture()) {
			this.texture.destroy();
		}
	}
	
}
